﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Threading;
using System.Windows.Threading;

namespace WpfHero
{
    /// <summary>
    /// Interaction logic for SongScroller.xaml
    /// </summary>
    public partial class SongScroller : UserControl
    {
        WHEngine engine;

        public SongScroller()
        {
            DataContextChanged += delegate { engine = ((WHEngine)DataContext); };
            InitializeComponent();
        }

        public void Start()
        {
            App.DoEvents();
            //grid.Width = grid.ActualWidth + stackPanel.Margin.Left;
            DoubleAnimation da = new DoubleAnimation
                                     {
                                         From = 0,
                                         To = (grid.ActualWidth * -1) + stackPanel.Margin.Left,
                                         Duration = new Duration(engine.EndOfSong)
                                     }; //-1 * (grid.ActualWidth), grid.ActualWidth / GemSizeConverter.MillisecondsPerPixel);
            
            stackPanel.RenderTransform = new TranslateTransform();
            stackPanel.RenderTransform.BeginAnimation(TranslateTransform.XProperty, da);
        }

    }
}
